import * as vscode from 'vscode';
import {dedent} from "../../../utils";

// documentation中使用了代码块，代码块中写的事makedown格式，首行不能为空
let quickCellItems = [
    {
        "label": "QuickCell_Create",
        "insertText": dedent`
        GUI:QuickCell_Create(\${1:parent}, \${2:"QuickCell_Create"}, \${3:0}, \${4:0}, \${5:587}, \${6:200}, \${7:function(quickParent)
            local item = GUI:Layout_Create(quickParent, "cell_", 0, 0, 571, 70)
            -- 图标
            local itemIcon = GUI:Image_Create(item, "item_icon", 80, 35, "res/01/010001.png")
            GUI:setAnchorPoint(itemIcon, 0.5, 0.5)
            -- name
            local itemDesc = GUI:Text_Create(item, "item_name", 120, 40, 20, "#D6C6AD", "name..1")
            -- tips
            local itemDesc = GUI:Text_Create(item, "item_desc", 120, 15, 16, "#D6C6AD", "tips")
            -- 分割线
            local Image_line = GUI:Image_Create(item, "item_line", 0, 0, "res/buff/bg_buffzy_02.png")
            GUI:setAnchorPoint(Image_line, 0.5, 0)
            GUI:setPosition(Image_line, 571/2, 0)
            return item
        end})
        `,
        "documentation": dedent`# 创建滚动容器子节点
        ## QuickCell_Create(parent, ID, x, y, w, h, createCB)

        | 参数     | 必选 | 类型     | 注释                                       |
        | :------- | :--- | :------- | :----------------------------------------- |
        | parent   | 是   | obj      | 父节点对象                                 |
        | ID       | 是   | string   | 唯一ID                                     |
        | x        | 是   | int      | 位置 横坐标                                |
        | y        | 是   | int      | 位置 纵坐标                                |
        | w        | 是   | int      | 宽度                                       |
        | h        | 是   | int      | 高度                                       |
        | createCB | 是   | function | 创建子节点内容回调 [函数返回 widget]       |
        | activeCB | 否   | function | 判断是否需要激活/创建 [函数返回 boolean值] |

        - 示例代码
        \`\`\`
        local listviewCells = GUI:ListView_Create(_parent, "listviewCells", 200, 80, 587, 200, 1)
        for i = 1, 10 do
            GUI:QuickCell_Create(listviewCells, "QuickCell_Create"..i, 0, 0, 587, 200,  function(quickParent)
                local item = GUI:Layout_Create(quickParent, "cell_", 0, 0, 571, 70)
                -- 图标
                local itemIcon = GUI:Image_Create(item, "item_icon", 80, 35, "res/01/010001.png")
                GUI:setAnchorPoint(itemIcon, 0.5, 0.5)
                -- name
                local itemDesc = GUI:Text_Create(item, "item_name", 120, 40, 20, "#D6C6AD", "name.."..i)
                -- tips
                local itemDesc = GUI:Text_Create(item, "item_desc", 120, 15, 16, "#D6C6AD", "tips")
                -- 分割线
                local Image_line = GUI:Image_Create(item, "item_line", 0, 0, "res/buff/bg_buffzy_02.png")
                GUI:setAnchorPoint(Image_line, 0.5, 0)
                GUI:setPosition(Image_line, 571/2, 0)
                return item
            end)
        end
        \`\`\`
        `
    },
    {
        "label": "QuickCell_Refresh",
        "insertText": dedent`
        GUI:QuickCell_Refresh(\${1:quickCell})
        `,
        "documentation": dedent`# 刷新展示
        ## QuickCell_Refresh(widget)

        | 参数   | 必选 | 类型 | 注释          |
        | :----- | :--- | :--- | :------------ |
        | widget | 是   | obj  | QuickCell对象 |
        `
    },
    {
        "label": "QuickCell_Exit",
        "insertText": dedent`
        GUI:QuickCell_Exit(\${1:quickCell})
        `,
        "documentation": dedent`# 强制退出/ 清理内容
        ## QuickCell_Exit(widget)

        | 参数   | 必选 | 类型 | 注释          |
        | :----- | :--- | :--- | :------------ |
        | widget | 是   | obj  | QuickCell对象 |

        \`\`\`
        -- 顺序使用 通常用于刷新单个cell内容 [可参照 GUILayout/AuctionPutList 等..]
        GUI:QuickCell_Exit(quickCell)
        GUI:QuickCell_Refresh(quickCell)
        \`\`\`
        `
    },
]



export function getCompletionItems(): vscode.CompletionItem[] {


    const completionItems: vscode.CompletionItem[] = [];
    quickCellItems.forEach((item: any) => {
        completionItems.push(createFunctionCompletionItem(item.label, item.insertText, item.documentation));
    });
    return completionItems;
}

function createFunctionCompletionItem(label: string, insertText: string, documentation?: string): vscode.CompletionItem {
    const item = new vscode.CompletionItem(label, vscode.CompletionItemKind.Function);
    item.insertText = new vscode.SnippetString(insertText);
    if (documentation) {
        item.documentation = new vscode.MarkdownString(documentation);
    }
    return item;
}
